package org.shj.pattern.strategy

abstract class Strategy {
  def getResult(total: Double): Double
}

class Normal extends Strategy{
  def getResult(total: Double): Double = {
    total
  }
}

class Rebate(val rebate: Double) extends Strategy{
  def getResult(total: Double): Double = {
    total * rebate
  }
}

/**
 * 满 多少 送多少
 */
class CashReduce(val man: Double, val red: Double) extends Strategy{
  def getResult(total: Double): Double = {
    total - (total.toInt)/man * red
  }
}

object StrategyFactory{
  def getStrategy(stype: String): Strategy = {
    stype match {
      case "N" => new Normal
      case "0.8" => new Rebate(0.8)
      case "满100返10" => new CashReduce(100, 10)
      case _ => throw new Exception
    }
  }
}